package com.findtech.threePomelos.utils;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.util.Log;
import android.view.View;

/**
 * Created by zhi.zhang on 12/25/15.
 */
public class TransitionController {

    private static final String TRANSLATION_Y = "translationY";
    private static final String TRANSLATION_X = "translationX";
    private static final String ALPHA = "alpha";


    public static Animator buildTranslationYAnimator(View view, int startY, int endY, int duration) {
        Animator animator = ObjectAnimator.ofFloat(view, TRANSLATION_Y, startY, endY);
        animator.setDuration(duration);
        return animator;
    }

    public static Animator buildTranslationXAnimator(View view, int startX, int endX, int duration) {
        Animator animator = ObjectAnimator.ofFloat(view, TRANSLATION_X, startX, endX);
        animator.setDuration(duration);
        return animator;
    }

    public static Animator buildAlphaAnimator(View view, float startAlpha, float endAlpha, int duration) {
        Animator animator = ObjectAnimator.ofFloat(view, ALPHA, startAlpha, endAlpha);
        animator.setDuration(duration);
        return animator;
    }

    public static Animator buildShowAnimator(View view, int duration) {
        return buildAlphaAnimator(view, 0f, 1f, duration);
    }

    public static Animator buildHideAnimator(View view, int duration) {
        return buildAlphaAnimator(view, 1f, 0f, duration);
    }

    /**
     * 上述接口,使用方法.
     * @param view
     * @param startX
     * @param endX
     * @param duration
     */
    void boyRightMoveAndGirlHidden(View view, int startX, int endX, int duration) {
        Log.d("ZZ", "boyRightMoveAndGirlHidden");
        AnimatorSet animatorSet = new AnimatorSet();
        Animator moveX = TransitionController.buildTranslationXAnimator(view, startX, endX, duration);
        Animator hideGirl = TransitionController.buildHideAnimator(view, duration);
        animatorSet.playTogether(moveX, hideGirl);
        animatorSet.start();
    }
}
